package com.ruoyi.matrix.service


import com.ruoyi.common.utils.DateUtils
import org.springframework.stereotype.Service
import com.ruoyi.matrix.mapper.CustomerMapper
import com.ruoyi.matrix.domain.Customer
import com.ruoyi.matrix.condition.CustomerCondition
import com.ruoyi.matrix.service.CustomerService

/**
 * 客户Service业务层处理
 * 
 * @author matrix
 * @date 2023-06-08
 */
@Service
class CustomerService(
    private val customerMapper: CustomerMapper,
) {

    fun getById(id: Long): Customer? {
        val condition = CustomerCondition()
        condition.id = id
        return this.get(condition)
    }

    fun select(customerCondition: CustomerCondition): List<Customer> {
        return customerMapper.selectCustomerList(customerCondition);
    }

    fun get(customerCondition: CustomerCondition): Customer? {
        customerCondition.limit(1)
        val list = this.select(customerCondition)
        return list.firstOrNull()
    }

    fun insert(customer: Customer): Int {
        return customerMapper.insertCustomer(customer)
    }

    fun update(customer: Customer): Int {
        return customerMapper.updateCustomer(customer)
    }

    fun deleteByIds(ids: Array<Long>): Int {
        return customerMapper.deleteCustomerByIds(ids)
    }

    fun deleteById(id: Long): Int {
        return customerMapper.deleteCustomerById(id)
    }

    fun count(condition: CustomerCondition): Long {
        return customerMapper.count(condition)
    }

    fun groupBy(condition: CustomerCondition): Customer? {
        val list  = customerMapper.groupByCustomer(condition)
        return list.firstOrNull()
    }
}